<!-- 样品详情 -->
<template>
	<view class="index">
		<view class="uni-card">
			<view class="uni-list">
				<view class="uni-list-cell">
					样品编码：{{listItem.is_xc == '1' ? '/': listItem.code}}
				</view>
				
				<view class="uni-list-cell">
					样品名称：{{(data.breed_type_id && data.breed_type_id.name) || ''}}  {{data.sample_name || ''}} 
				</view>
				
				<view class="uni-list-cell">
					采样地点：{{data.location_id || '未填写'}}
				</view>
				
				<!-- <view class="uni-list-cell">
					采样天数：{{data.date_num || ''}}
				</view> -->
				
				<view class="uni-list-cell">
					份数：{{data.number || ''}}份
				</view>
				
				<!-- <view class="uni-list-cell">
					频次：{{data.rate_num|| ''}}
				</view> -->
				
				<view class="uni-list-cell">
					状态：{{listItem.state || ''}}
				</view>
				
				<view class="uni-list-cell-divider">
					<!--  #ifdef MP-WEIXIN -->
					检测项目：{{data.item_type_id && data.item_type_id.name}}
					<!--  #endif -->
					<!--  #ifdef APP-PLUS -->
					检测项目：<text v-html="data.item_type_id && data.item_type_id.name"></text>
					<!--  #endif -->				
				</view>
				<view class="uni-list-cell con-list" v-if="data.item_id">
					<!--  #ifdef MP-WEIXIN -->
					<text v-for="(item, index) in data.item_id" :key="index">项目名称：{{item.name}}</text>
					<!--  #endif -->
					<!--  #ifdef APP-PLUS -->
					<text v-for="(item, index) in data.item_id" :key="index">项目名称：<text v-html="item.name"></text></text>
					<!--  #endif -->	
				</view>
				
				<view class="uni-list-cell-divider" v-if="data.sampling_standard && data.sampling_standard.type_name">
					<view class="width-auto">采样标准：</view>
					<view hover-class="uni-list-cell-hover" class="width-100 standard-view" v-if="data.sampling_standard && data.sampling_standard.file" @click="openFile()">点击查看采样标准</view>
				</view>
				<view class="uni-list-cell con-list"  style="flex-flow:row wrap;" v-if="data.sampling_standard && data.sampling_standard.type_name">
					<view class="width-f100">
						<view class="width-f100 standard-view">{{data.sampling_standard.type_name}}</view>
						<view class="width-f100"><rich-text :nodes="data.sampling_standard.remark"></rich-text></view>
					</view> 
				</view>
			</view>
		</view>
		
		<!-- <view class="btn-row uni-flex" v-if="listItem.state == '采样中'">
			<button type="primary" class="primary uni-flex-item" @tap="addSample">updateSample</button>
		</view> -->
	</view>
</template>

<script>
	
	import net from '../../net.js';
	import service from '../../service.js';
	import utils from '../../common/utils.js';
	
	export default {
		data() {
			return {
				data: {},
				sampleId: '',//样品id
				codeId: '',//编码id
				listItem: {},//列表内容
				filePath: ''//文件路径
			}
		},
		onLoad(res) {
			this.data = {};
			this.listItem = {};
			if(res.listItem) this.listItem = JSON.parse(res.listItem);
			this.sampleId = res.sampleId;
			this.codeId = res.codeId;
			this.getDetail();
		},
		methods: {
			getDetail() {
				net.netGet('/module/api/main/getEditSampleInfo/'+encodeURIComponent(this.sampleId), {}, (res)=>{
					//console.log(res);
					this.data = res || {};
					if(this.data.sampling_standard && this.data.sampling_standard.remark) {
						this.data.sampling_standard.remark = this.data.sampling_standard.remark.replace(/neue\';"=""/g, '');
					}
				}, ()=>{
					uni.showToast({icon: 'none', title: '无法获取样品详情'});
				}, (res)=> {
					
				});	
			},
			updateSample() {
				if(this.listItem && this.listItem.state == '采样中') {
					let param = utils.toParam({codeId: this.codeId, data: this.data});
					uni.redirectTo({
						url: "./sample_add"+param
					});
				}
			},
			goSamplingStandard() {
				let param = utils.toParam({standardId: this.data.sampling_standard.id});
				uni.navigateTo({
					url: "./sample_standard"+param
				});
			},
			openFile() {
				if(this.filePath) {
					uni.openDocument({
					  filePath: this.filePath,
					  success: (res)=> {
						console.log('打开文档成功');
					  },
					  fail:() =>{
					  	uni.showToast({icon: 'none',title: '无法打开文件'});
					  }
					});
				}else {
					uni.downloadFile({
					  url: this.data.sampling_standard.file,
					  success: (res)=> {
						this.filePath = res.tempFilePath;
						uni.openDocument({
						  filePath: this.filePath,
						  success: (res)=> {
							console.log('打开文档成功');
						  },
						  fail: ()=> {
						  	uni.showToast({icon: 'none',title: '无法打开文件'});
						  }
						});
					  },
					  fail: ()=> {
					  	uni.showToast({icon: 'none',title: '无法打开文件'});
					  }
					});
				}
			}
		},
	}
</script>

<style>
	.index{
		width: 100%;
	}
	.uni-card {
		margin: 50upx 0 60upx 0;
	}
	
	.uni-list-cell:after {
		left: 0;
		height: 0;
	}
	
	.uni-list-cell {
		padding: 0 20upx;
		min-height: 90upx;
		color: #666;
	}
	
	.uni-list-cell.con-list {
		flex-wrap: wrap;
		padding: 10upx 0;
	}
	
	.uni-list-cell.con-list text {
		flex: 0 0 100%;
		font-size: 32upx;
	}
	
	.uni-list-cell-divider ~ .uni-list-cell {
		padding-left: 50upx;
		min-height: 70upx;
	}
	
	.standard-view {
		padding-right: 70upx;
	}
	
	.uni-list-cell.no-left {
		padding-left: 20upx;
	}
	
	.check-item {
		
	}
	
</style>
